import { addPropertyfeeAPI, deletePropertyfeeAPI, fetchBuildingListAPI, fetchEnterpriseListAPI, fetchPropertyfeeListAPI } from '@/api/propety'

const actions = {
  /* 发送请求获取物业费列表的action */
  async fetchPropertyfeeList(context, pageParams) {
    const { data } = await fetchPropertyfeeListAPI(pageParams)
    context.commit('updatePropertyfeeList', data)
  },
  /* 发送请求删除物业费的action */
  async deletePropertyfee(context, id) {
    const { msg } = await deletePropertyfeeAPI(id)
    return msg
  },
  /* 发送请求添加账单的action */
  async addPropertyfee(context, formData) {
    const { msg } = await addPropertyfeeAPI(formData)
    return msg
  },
  /* 发送请求获取租赁楼宇列表的action */
  async fetchBuildingList(context) {
    const { data } = await fetchBuildingListAPI()
    context.commit('updateBuildingList', data)
  },
  /* 发送请求获取企业列表的action */
  async fetchEnterpriseList(context) {
    const { data } = await fetchEnterpriseListAPI()
    context.commit('updateEnterpriseList', data)
  }
}
const mutations = {
  /* 更新物业费列表的mutation */
  updatePropertyfeeList(state, propertyfeeInfo) {
    state.propertyfeeInfo = propertyfeeInfo
  },
  /* 更新租赁楼宇列表的mutation */
  updateBuildingList(state, buildingList) {
    state.buildingList = buildingList
  },
  /* 更新企业列表的mutation */
  updateEnterpriseList(state, enterpriseList) {
    state.enterpriseList = enterpriseList
  }
}
const state = () => {
  return {
    propertyfeeInfo: {},
    buildingList: [],
    enterpriseList: []
  }
}

const getters = {
  propertyfeeList(state) {
    return state.propertyfeeInfo.rows
  },
  total(state) {
    return state.propertyfeeInfo.total
  }
}

export default {
  actions,
  mutations,
  state,
  getters,
  namespaced: true
}
